package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.controller.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author zt
 * @since 2024-08-21
 */
@RestController
@RequestMapping("/lessons")
@Api(tags = "我的课表相关接口")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService lessonService;

    /***
     * 分页查询我的课表
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("查询我的课表，排序字段latest_learn_time:学习时间排序，create_time：购买时间排序")
    public PageDTO<LearningLessonVO> queryMyLessions(PageQuery query){
        return lessonService.queryMyLession(query);
    }

    /***
     * 查询正在学习的课程
     * @return
     */
    @GetMapping("/now")
    @ApiOperation("查询正在学习的课程")
    public LearningLessonVO queryMyCurrentLession(){
        return lessonService.queryMyCurrentLession();
    }

    /***
     * 创建学习计划
     * @param planDTO
     */
    @ApiOperation("创建学习计划")
    @PostMapping("/plans")
    public void createLearningPlan(@Valid @RequestBody LearningPlanDTO planDTO){
        lessonService.createLearningPlan(planDTO.getCourseId(),planDTO.getFreq());
    }

    /***
     * 查询我的学习计划
     * @param query
     * @return
     */
    @ApiOperation("查询我的学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlan(PageQuery query){
        return lessonService.queryMyPlan(query);
    }
}
